#!/usr/bin/python
# -*- coding: UTF-8 -*-
import pygame
import sys


# 颜色定义
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
RED_B = (160, 48, 0)  # 基地里面的红色
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)
GREY_ = (127, 127, 127)
ORG__ = (192, 112, 0)  # 橙色 ORANGE - 土墙
TEXT_COLOR = pygame.Color(255, 255, 0)  # 字体颜色

# 常量
Magnification = 10  # 16乘以16像素的图案的放大倍数，即112x112像素

base = [
    [BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK],
    [GREY_, GREY_, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, GREY_, GREY_],
    [BLACK, GREY_, GREY_, BLACK, BLACK, BLACK, GREY_, GREY_, GREY_, BLACK, BLACK, BLACK, BLACK, GREY_, GREY_, BLACK],
    [GREY_, GREY_, GREY_, GREY_, BLACK, BLACK, BLACK, GREY_, RED_B, GREY_, BLACK, BLACK, GREY_, GREY_, GREY_, GREY_],
    [BLACK, GREY_, GREY_, GREY_, BLACK, BLACK, BLACK, GREY_, GREY_, BLACK, BLACK, BLACK, GREY_, GREY_, GREY_, BLACK],
    [GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, BLACK, GREY_, GREY_, BLACK, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_],
    [BLACK, BLACK, GREY_, RED_B, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, RED_B, GREY_, BLACK, BLACK],
    [BLACK, GREY_, GREY_, GREY_, RED_B, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, RED_B, GREY_, GREY_, GREY_, BLACK],
    [BLACK, BLACK, GREY_, GREY_, GREY_, GREY_, RED_B, GREY_, GREY_, RED_B, GREY_, GREY_, GREY_, GREY_, BLACK, BLACK],
    [BLACK, BLACK, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, BLACK, BLACK],
    [BLACK, BLACK, BLACK, GREY_, GREY_, GREY_, BLACK, GREY_, GREY_, BLACK, GREY_, GREY_, GREY_, BLACK, BLACK, BLACK],
    [BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, GREY_, GREY_, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK],
    [BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, GREY_, GREY_, GREY_, GREY_, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK],
    [BLACK, BLACK, BLACK, BLACK, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, BLACK, BLACK, BLACK, BLACK],
    [BLACK, BLACK, BLACK, BLACK, GREY_, GREY_, BLACK, GREY_, GREY_, BLACK, GREY_, GREY_, BLACK, BLACK, BLACK, BLACK],
    [BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK]
]

wall = [
    [BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK],
    [GREY_, GREY_, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, GREY_, GREY_],
    [BLACK, GREY_, GREY_, BLACK, BLACK, BLACK, GREY_, GREY_, GREY_, BLACK, BLACK, BLACK, BLACK, GREY_, GREY_, BLACK],
    [GREY_, GREY_, GREY_, GREY_, BLACK, BLACK, BLACK, GREY_, RED_B, GREY_, BLACK, BLACK, GREY_, GREY_, GREY_, GREY_],
    [BLACK, GREY_, GREY_, GREY_, BLACK, BLACK, BLACK, GREY_, GREY_, BLACK, BLACK, BLACK, GREY_, GREY_, GREY_, BLACK],
    [GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, BLACK, GREY_, GREY_, BLACK, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_],
    [BLACK, BLACK, GREY_, RED_B, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, RED_B, GREY_, BLACK, BLACK],
    [BLACK, GREY_, GREY_, GREY_, RED_B, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, RED_B, GREY_, GREY_, GREY_, BLACK],
    [BLACK, BLACK, GREY_, GREY_, GREY_, GREY_, RED_B, GREY_, GREY_, RED_B, GREY_, GREY_, GREY_, GREY_, BLACK, BLACK],
    [BLACK, BLACK, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, BLACK, BLACK],
    [BLACK, BLACK, BLACK, GREY_, GREY_, GREY_, BLACK, GREY_, GREY_, BLACK, GREY_, GREY_, GREY_, BLACK, BLACK, BLACK],
    [BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, GREY_, GREY_, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK],
    [BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, GREY_, GREY_, GREY_, GREY_, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK],
    [BLACK, BLACK, BLACK, BLACK, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, GREY_, BLACK, BLACK, BLACK, BLACK],
    [BLACK, BLACK, BLACK, BLACK, GREY_, GREY_, BLACK, GREY_, GREY_, BLACK, GREY_, GREY_, BLACK, BLACK, BLACK, BLACK],
    [BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK]
]


def drawSquare(multiple, base_i):
    for x in range(16):
        for y in range(16):
            pygame.draw.rect(window, base_i[y][x],
                (x * (multiple - 1), y * (multiple - 1), 1 * multiple, 1 * multiple))  # 在每个像素位置绘制一个1x1的矩形

# 初始化Pygame
pygame.init()

# 设置窗口大小
window_size = (256, 256)
window = pygame.display.set_mode(window_size)
pygame.display.set_caption("16x16 Pixel Square")

# 设置时钟，用于控制帧率
clock = pygame.time.Clock()

# 主循环
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # 填充窗口背景色为白色
    window.fill((255, 255, 255))

    drawSquare(Magnification, base)

    # for x in range(16):
    #     for y in range(16):
    #         pygame.draw.rect(window, base[x][y], (x, y, 1, 1))  # 在每个像素位置绘制一个1x1的矩形

    # 绘制16x16像素的正方形，每个像素颜色不同
    # for x in range(16):
    #     for y in range(16):
    #         # 计算每个像素的位置和颜色（这里简单使用x和y作为颜色的组成部分）
    #         color = (x * 16, y * 16, (x + y) * 16 % 256)  # 示例颜色计算方式，可根据需要调整
    #         pygame.draw.rect(window, color, (x, y, 1, 1))  # 在每个像素位置绘制一个1x1的矩形

    # 更新屏幕显示
    pygame.display.flip()

    # 控制帧率，避免过快刷新导致的问题
    clock.tick(30)

# 退出Pygame
pygame.quit()
sys.exit()